/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.logist;

import dp1.titandevelop.titano.bean.Estado;
import dp1.titandevelop.titano.persistent.Cotizacion;
import dp1.titandevelop.titano.persistent.Proveedor;
import dp1.titandevelop.titano.service.CotizacionService;
import dp1.titandevelop.titano.service.ProveedorService;
import dp1.titandevelop.titano.service.RequerimientoService;
import dp1.titandevelop.titano.service.ValidacionService;
import java.awt.Dimension;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author chrestean
 */
public class AdministrarCotizaciones extends javax.swing.JInternalFrame {

    /**
     * Creates new form TitanoInteralSegADMUser
     */
    public List<Proveedor> lista;
    
    private ModulosT_LOG_NuevaOrdCompra caller = null;

    
    private void addList (List<Proveedor> lista){
        
        for(int i=0;i<lista.size();i++){
            this.cmdProv.addItem(lista.get(i).getRazonsocial());
        }
    }
    public void habilitaBotones(){
        this.btnEditar.setEnabled(true);
        this.btnDetalle.setEnabled(true);
        this.btnEliminar.setEnabled(true);
    }
    private void inhabilitaBotones(){
        this.btnDetalle.setEnabled(false);
        this.btnEditar.setEnabled(false);
        this.btnEliminar.setEnabled(false);
    }
    public void RefreshTable() {
        AbstractTableModel aux = (AbstractTableModel)jTable1.getModel();
        aux.fireTableDataChanged();
    }
    public AdministrarCotizaciones() {
        initComponents();
        this.jButton3.setVisible(false);
        this.listaCotizaciones = new ArrayList<Cotizacion>();
        this.jTable1.setModel(modelo);

        ValidacionService vs = new ValidacionService();
        vs.NoEscribe(dpFechaRecepcion);
        vs.NoEscribe(this.dpFechaCotizacion);
       ProveedorService serv = new ProveedorService();
       lista = serv.buscarTodos();
       addList(lista);
       this.inhabilitaBotones();
    }
    public AdministrarCotizaciones(ModulosT_LOG_NuevaOrdCompra caller, int idProveedor) {
        initComponents();
        this.btnNuevo.setVisible(false);
        this.btnLimpiar.setVisible(false);

        this.setTitle("Seleccionar cotizacion");
        this.btnEditar.setVisible(false);
        this.btnEliminar.setVisible(false);
        this.listaCotizaciones = new ArrayList<Cotizacion>();
        this.jTable1.setModel(modelo);
        this.caller = caller;
        this.closable = false;
        this.inhabilitaBotones();

    }
    private ArrayList<Cotizacion> listaCotizaciones;
    private AbstractTableModel modelo = new AbstractTableModel() {
        public int getRowCount() {
            return listaCotizaciones.size();
        }

        public int getColumnCount() {
            return 8;

        }

        public Object getValueAt(int fi, int co) {
            DateFormat fecha = DateFormat.getDateInstance(DateFormat.MEDIUM);

            switch (co) {
                case 1:
                    return listaCotizaciones.get(fi).getDetalleCotizacionArray().get(0).getToRequerimientoXProducto().getToRequerimiento().getIdrequerimiento();
                case 0:
                    return listaCotizaciones.get(fi).getIdcotizacion();
                case 2:
                    return listaCotizaciones.get(fi).getToProveedor().getRazonsocial();
                case 3:
                    return listaCotizaciones.get(fi).getToOrdenCompra().getIdordencompra();
                case 4:
                    return new SimpleDateFormat("dd-MM-yyyy").format(listaCotizaciones.get(fi).getFecharegistro());
                case 5:
                    return new SimpleDateFormat("dd-MM-yyyy").format(listaCotizaciones.get(fi).getFecharecepcion());
                case 6:
                    return "S/."+new DecimalFormat("#.##").format(listaCotizaciones.get(fi).getPreciototal());
                case 7:
                    return Estado.devuelveCadena(listaCotizaciones.get(fi).getEstado());
            }
            return null;

        }

        @Override
        public String getColumnName(int col) {
            String[] titles = {"Cotización", "Requerimiento", "Proveedor", "Orden de Compra", "Fecha de Registro", "Fecha de Recepción", "Monto", "Estado"};
            return titles[col];
        }
    };

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        dpFechaCotizacion = new org.jdesktop.swingx.JXDatePicker();
        jLabel1 = new javax.swing.JLabel();
        dpFechaRecepcion = new org.jdesktop.swingx.JXDatePicker();
        cmdProv = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btnBuscar = new javax.swing.JButton();
        btnNuevo = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(3, 0), new java.awt.Dimension(3, 0), new java.awt.Dimension(3, 32767));
        btnEditar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767));
        btnDetalle = new javax.swing.JButton();

        setResizable(true);
        setTitle("Administracion de Cotizaciones");
        setMaximumSize(new java.awt.Dimension(630, 480));
        setMinimumSize(new java.awt.Dimension(630, 480));
        setPreferredSize(new java.awt.Dimension(630, 480));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtros de Búsqueda"));
        jPanel1.setFont(new java.awt.Font("Tekton Pro", 0, 11)); // NOI18N

        jLabel9.setText("Proveedor");

        jLabel12.setText("Fecha Cotizacion");

        jLabel1.setText("Fecha Recepción");

        dpFechaRecepcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dpFechaRecepcionActionPerformed(evt);
            }
        });

        cmdProv.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jLabel9))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel12)))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cmdProv, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dpFechaCotizacion, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(dpFechaRecepcion, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cmdProv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel12)
                        .addComponent(dpFechaCotizacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(dpFechaRecepcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultado de Búsqueda"));
        jPanel2.setFont(new java.awt.Font("Tekton Pro", 0, 11)); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Requerimiento", "Cotizacion", "Proveedor", "Producto", "Monto Cotizacion", "Estado"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/buscar.png"))); // NOI18N
        btnBuscar.setToolTipText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/nuevo.png"))); // NOI18N
        btnNuevo.setToolTipText("Nuevo");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/limpiar.png"))); // NOI18N
        btnLimpiar.setToolTipText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/retroceder.png"))); // NOI18N
        btnSalir.setToolTipText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/editar.png"))); // NOI18N
        btnEditar.setEnabled(false);
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/eliminar.png"))); // NOI18N
        btnEliminar.setEnabled(false);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/asignar.png"))); // NOI18N
        jButton3.setEnabled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        btnDetalle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/detalle.png"))); // NOI18N
        btnDetalle.setToolTipText("Detalle");
        btnDetalle.setEnabled(false);
        btnDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetalleActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnBuscar)
                        .addGap(1, 1, 1)
                        .addComponent(btnNuevo)
                        .addGap(1, 1, 1)
                        .addComponent(btnLimpiar)
                        .addGap(1, 1, 1)
                        .addComponent(btnSalir)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jButton3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(56, 56, 56))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(btnDetalle)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnSalir)
                    .addComponent(btnBuscar)
                    .addComponent(btnNuevo)
                    .addComponent(btnLimpiar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnEliminar)
                            .addComponent(jButton3)
                            .addComponent(btnEditar))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnDetalle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                        .addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed

       ProveedorService ps = new ProveedorService();
       RequerimientoService rs = new RequerimientoService();
       if ( ps.buscarTodos().size() > 0 && rs.buscarTodo().size() >0) {
        ModulosT_LOG.cotizaNuevo = new ModulosT_LOG_NuevaCotizacion();
        this.getParent().add(ModulosT_LOG.cotizaNuevo);
        
        Dimension desktopSize = this.getParent().getSize();
        Dimension jInternalFrameSize = ModulosT_LOG.cotizaNuevo.getSize();
        ModulosT_LOG.cotizaNuevo.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                (desktopSize.height - jInternalFrameSize.height)/4 );
        ModulosT_LOG.cotizaNuevo.show();
        this.dispose();
        //.hide();
       } else {
           // mensaje de error
           JOptionPane.showMessageDialog(this, "No hay proveedores o requerimientos registrados.", "Aviso!", JOptionPane.WARNING_MESSAGE);
       }
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        // TODO add your handling code here:
        this.cmdProv.setSelectedIndex(0);
        
        this.dpFechaCotizacion.setDate(null);
        this.dpFechaRecepcion.setDate(null);
        this.listaCotizaciones.clear();
        this.modelo.fireTableDataChanged();
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:

        if (this.caller != null) {
            this.caller.show();
        }
        this.dispose();
    }//GEN-LAST:event_btnSalirActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:

        CotizacionService cs = new CotizacionService();
        ValidacionService val = new ValidacionService();
        
        if (this.cmdProv.getSelectedIndex() - 1 == -1){
            if ( val.esFechaVacia(dpFechaRecepcion) && val.esFechaVacia(this.dpFechaCotizacion)){
                this.listaCotizaciones = cs.buscarTodos(null);
            }else{

                this.listaCotizaciones = cs.buscarPor(this.dpFechaRecepcion.getDate(),
                        this.dpFechaCotizacion.getDate());
            }
            
        }
        else {
            if ( val.esFechaVacia(dpFechaRecepcion)&&val.esFechaVacia(this.dpFechaCotizacion)){
                this.listaCotizaciones = cs.buscarPor(lista.get(this.cmdProv.getSelectedIndex()-1).getIdproveedor());
            }else{

                this.listaCotizaciones = cs.buscarPor( lista.get(this.cmdProv.getSelectedIndex()-1).getIdproveedor(),this.dpFechaRecepcion.getDate(),
                        this.dpFechaCotizacion.getDate());
            }
            
        }
            
        this.RefreshTable();
        
        
       

        this.modelo.fireTableDataChanged();

    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed

        if (this.listaCotizaciones.get(this.jTable1.getSelectedRow()).getEstado() != Estado.getEstadoId("Entregado") || this.listaCotizaciones.get(this.jTable1.getSelectedRow()).getFecharecepcion().after(new Date())) {
            ModulosT_LOG_EditarCotizacion ec = new ModulosT_LOG_EditarCotizacion(this, this.listaCotizaciones.get(this.jTable1.getSelectedRow()));
            this.getParent().add(ec);
             Dimension desktopSize = this.getParent().getSize();
             Dimension jInternalFrameSize = ec.getSize();
                ec.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                (desktopSize.height - jInternalFrameSize.height) / 4);
            ec.show();
            //this.hide();

        } else {
            // mensaje de error
            JOptionPane.showMessageDialog(this, "La cotización seleccionada ya no es editable. Ya fue entregada o ya no se encuentra pendiente.", "Cotización", JOptionPane.ERROR_MESSAGE);
        }


    }//GEN-LAST:event_btnEditarActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:
        
         if(evt.getClickCount()==1){
            this.habilitaBotones();
        }
         if (this.caller != null) {
            this.jButton3.setEnabled(true);
            this.btnDetalle.setEnabled(true);
        }


    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
//        if ( this.listaCotizaciones.get(this.jTable1.getSelectedRow()).getToOrdenCompra().getIdordencompra().equals(0)) {
//            JOptionPane.showMessageDialog(this, "La cotizacion aún no tiene una orden de compra asignada.", "Asignacion", JOptionPane.ERROR_MESSAGE);
//            return;
//        }

        if (!this.caller.agregarCotizacion(this.listaCotizaciones.get(this.jTable1.getSelectedRow()))) {
            JOptionPane.showMessageDialog(this, "La cotizacion ya fue agregada", "Asignacion", JOptionPane.ERROR_MESSAGE);
        } else {
            this.dispose();
            this.caller.show();
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        int confirmar = JOptionPane.showInternalConfirmDialog(this.getRootPane(),"¿Está seguro que desea eliminar el registro?","Aviso!",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
            if (JOptionPane.OK_OPTION == confirmar)
                {   this.listaCotizaciones.get(this.jTable1.getSelectedRow()).setEstado(0);
                    this.listaCotizaciones.get(this.jTable1.getSelectedRow()).getObjectContext().commitChanges();
                    this.listaCotizaciones.remove(this.jTable1.getSelectedRow());
                }

        this.RefreshTable();
        this.inhabilitaBotones();
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void dpFechaRecepcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dpFechaRecepcionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dpFechaRecepcionActionPerformed

    private void btnDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetalleActionPerformed

        
        
            ModulosT_LOG_DetalleCotizacion ec = new ModulosT_LOG_DetalleCotizacion(this, this.listaCotizaciones.get(this.jTable1.getSelectedRow()));
            this.getParent().add(ec);
             Dimension desktopSize = this.getParent().getSize();
             Dimension jInternalFrameSize = ec.getSize();
                ec.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                (desktopSize.height - jInternalFrameSize.height) / 4);
            ec.show();
            //this.hide();

        

    }//GEN-LAST:event_btnDetalleActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnDetalle;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JButton btnSalir;
    private javax.swing.JComboBox cmdProv;
    private org.jdesktop.swingx.JXDatePicker dpFechaCotizacion;
    private org.jdesktop.swingx.JXDatePicker dpFechaRecepcion;
    private javax.swing.Box.Filler filler1;
    private javax.swing.Box.Filler filler2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    private void setLocationRelativeTo(Object object) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    private Object getparent() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
